<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .container{
            display: flex;
            width:170px;
            justify-content: space-between;

        }
        .container > div{
            width:40px;
            height: 40px;
            background-color: #ccc;
            text-align: center;
            line-height: 40px;
            color:white;
        }
    </style>
    <script>
        function a(){
            var inputDom=document.querySelector("input");
            var num=inputDom.value*1+1;
            inputDom.value=num;
        }
        function b(){
            var inputDom=document.querySelector("input");
            var num=inputDom.value*1;
            if(num>0){
                num=num-1;
                inputDom.value=num;
            }else{
                alert("不能再减了！！！");
            }
           
        }
    </script>
</head>
<body>
    <div class="container">
        <div onclick="b()">-</div> 
        <input type="text" value="0" size="3">
        <div onclick="a()">+</div>
    </div>
 
</body>
</html>